package hjw.com.util;

import com.fasterxml.jackson.databind.ObjectMapper;
import org.slf4j.Logger;

/**
 * @author maste
 */
public class PackJsn {

    public static Logger logger = org.slf4j.LoggerFactory.getLogger(PackJsn.class);

    public static ObjectMapper mapper = new ObjectMapper();

    public static String pack(int code, String msg, Object data) {
        Data da = new Data(code, msg, data);
        String json = "";
        try {
            json = mapper.writeValueAsString(da);
        } catch (Exception e) {
            logger.error("json序列化失败", e);
        }
        logger.debug("JSON = " + json);
        return json;
    }

    public static String pack(int code, String msg) {
        Data da = new Data(code, msg, null);
        String json = "";
        try {
            json = mapper.writeValueAsString(da);
        } catch (Exception e) {
            logger.error("json序列化失败", e);
        }
        logger.debug("JSON = " + json);
        return json;
    }

}
